/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.iti.jets.gpts.bean;

import com.iti.jets.gpts.pojo.AttributeType;
import com.iti.jets.gpts.pojo.Point;
import com.iti.jets.gpts.pojo.Terminal;
import com.iti.jets.gpts.pojo.TranService;
import com.iti.jets.gpts.pojo.TranServiceAttribute;
import com.iti.jets.gpts.pojo.TranServiceRoute;
import com.iti.jets.gpts.pojo.TranServiceType;
import com.iti.jets.gpts.pojo.TranServiceTypeAttribute;
import com.iti.jets.gpts.pojo.TranServiceTypeAttributeType;
import com.iti.jets.gpts.service.AttributeTypeService;
import com.iti.jets.gpts.service.PointService;
import com.iti.jets.gpts.service.TranServiceService;
import com.iti.jets.gpts.service.ViewTransServiceTypeAtt;
import com.sun.jersey.api.client.UniformInterfaceException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import org.codehaus.jettison.json.JSONException;
import org.primefaces.event.FlowEvent;
import org.primefaces.event.map.OverlaySelectEvent;
import org.primefaces.model.map.Circle;
import org.primefaces.model.map.DefaultMapModel;
import org.primefaces.model.map.LatLng;
import org.primefaces.model.map.MapModel;
import org.primefaces.model.map.Marker;

/**
 *
 * @author khalifaabdelaziz
 */
@ManagedBean
@ViewScoped
public class TranServiceBeanWizerd implements Serializable {

    private TranServiceService tss;
    private TranService tranService = new TranService();
    private TranServiceType TST = new TranServiceType();
    private PointService pointService;
    private ViewTransServiceTypeAtt vtsta;
    private AttributeTypeService ats;
//    TST and It's AT
    private Map<String, String> tST = new HashMap<String, String>();
    private String tstid;
    private DataModel<TranServiceTypeAttribute> tSTAttributeTypes = new ListDataModel<TranServiceTypeAttribute>();
//=====================
    private Map<String, String> aT = new HashMap<String, String>();
    private String atid;
    private String atvalue;
    private List<TranServiceAttribute> tranServiceAttributesList = new ArrayList<TranServiceAttribute>();
    private DataModel<TranServiceAttribute> tranServiceAttributesDataModel = new ListDataModel<TranServiceAttribute>();
//=====================
    // TS MAP LNG ,LAT Source and dest
    private List<Point> aPoints = new ArrayList<Point>();
    private List<Point> hPoints = new ArrayList<Point>();
    private Terminal t1 = new Terminal(new Point());
    private Terminal t2 = new Terminal(new Point());
//===================== 
//=====================map   
    private boolean Saved;
    private int counter = 0;
    private String title;
    private double lat;
    private double lng;
    private String type;
    private double t1Lat;
    private double t1Lng;
    private double t2Lat;
    private double t2Lng;
    private MapModel simpleModel;
    private String request = "";
    private String requesth = "";
    private List<Marker> terminalMarkers = new ArrayList<Marker>();
    private List<Marker> pointsMarkers = new ArrayList<Marker>();
    private List<Marker> hpointsMarkers = new ArrayList<Marker>();
    private List<Terminal> terminals = new ArrayList<Terminal>();
    private List<Point> points = new ArrayList<Point>();
    private List<TranServiceRoute> tsrs = new ArrayList<TranServiceRoute>();
//=====================map
    private boolean skip;

    private static Logger logger = Logger.getLogger(TranServiceBeanWizerd.class.getName());

    public TranServiceBeanWizerd() {
        tss = new TranServiceService();
        try {
            pointService = new PointService();
            List<Terminal> allpoints = pointService.getAllpoints();
            simpleModel = new DefaultMapModel();
            for (Terminal terminal : allpoints) {
                if (terminal.getIdPoint() != -1) {
                    terminals.add(terminal);
                    Marker marker2 = new Marker(toLatLng(terminal.getPoint().getLocation()), terminal.getPoint().getName(), terminal.getIdPoint(), "http://localhost:8080/GPAdminWebApplication/resources/images/terminal.png");
                    marker2.setZindex(-1);
                    points.add(terminal.getPoint());
                    simpleModel.addOverlay(marker2);
                } else if (terminal.getPoint().getIsStop()) {
                    points.add(terminal.getPoint());
                    Marker marker2 = new Marker(toLatLng(terminal.getPoint().getLocation()), terminal.getPoint().getName(), terminal.getPoint().getId(), "http://localhost:8080/GPAdminWebApplication/resources/images/stop.png");
                    marker2.setZindex(-1);
                    simpleModel.addOverlay(marker2);
                } else {
                    points.add(terminal.getPoint());
                    Marker marker2 = new Marker(toLatLng(terminal.getPoint().getLocation()), terminal.getPoint().getName(), terminal.getPoint().getId(), "http://localhost:8080/GPAdminWebApplication/resources/images/point.png");
                    marker2.setZindex(-1);
                    simpleModel.addOverlay(marker2);
                }
            }
            try {
                vtsta = new ViewTransServiceTypeAtt();
                ats = new AttributeTypeService();
                List<TranServiceType> tranServiceTypes = vtsta.getTranServiceTypes();
                for (TranServiceType tranServiceType : tranServiceTypes) {
                    tST.put(tranServiceType.getName(), "" + tranServiceType.getId());
                }
                List<AttributeType> allAttribute = ats.getAllAttribute();
                for (AttributeType attributeType : allAttribute) {

                    aT.put(attributeType.getName(), "" + attributeType.getId());

                }

            } catch (UniformInterfaceException ex) {
                Logger.getLogger(TranServiceBeanWizerd.class.getName()).log(Level.SEVERE, null, ex);
            } catch (JSONException ex) {
                Logger.getLogger(TranServiceBeanWizerd.class.getName()).log(Level.SEVERE, null, ex);
            }

        } catch (UniformInterfaceException ex) {
            Logger.getLogger(TranServiceBeanWizerd.class.getName()).log(Level.SEVERE, null, ex);
        } catch (JSONException ex) {
            Logger.getLogger(TranServiceBeanWizerd.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    public void save(ActionEvent actionEvent) {
        //Persist user  

        FacesMessage msg = new FacesMessage("Successful", "Added :" + tranService.getName());
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }

    public String onFlowProcess(FlowEvent event) {
        logger.info("Current wizard step:" + event.getOldStep());
        logger.info("Next step:" + event.getNewStep());
        if (event.getNewStep().equals("tsrw")) {
            Saved = false;
        }
        if (event.getNewStep().equals("tsrh")) {
            if (terminalMarkers.size() == 2) {
                aPoints.clear();
                for (Terminal terminal : terminals) {
                    if (Integer.parseInt(terminalMarkers.get(0).getData().toString()) == terminal.getPoint().getId()) {
                        t1 = terminal;
                    } else if (Integer.parseInt(terminalMarkers.get(1).getData().toString()) == terminal.getPoint().getId()) {
                        t2 = terminal;
                    }
                }
             //   System.out.println("for (Marker marker : pointsMarkers)====================" + pointsMarkers.size());
                for (Marker marker : pointsMarkers) {
                    for (Point point : points) {
               //         System.out.println("for (Point point : points)====================for (Marker marker : pointsMarkers) : " + Integer.parseInt(marker.getData().toString()) + point.getId());
                        if (Integer.parseInt(marker.getData().toString()) == point.getId()) {
                //            System.out.println("aPoints.add(point);====================" + point.getId() + point.getName());
                            aPoints.add(point);
                            break;
                        }
                    }
                }

                Saved = true;
                return event.getNewStep();

            } else {

                FacesContext context = FacesContext.getCurrentInstance();
                context.addMessage(null, new FacesMessage("Draw Away Route", "you Must Draw your transportation route"));
                return event.getOldStep();
            }
        }
        if (event.getNewStep().equals("confirm")) {
            hPoints.clear();
            for (Marker marker : hpointsMarkers) {
                for (Point point : points) {

                    if (Integer.parseInt(marker.getData().toString()) == point.getId()) {
                        hPoints.add(point);
                    }
                }
            }
            /////
            tranService.setTranServiceType(TST);
            tranService.getTranServiceAttributes().addAll(tranServiceAttributesList);

            tsrs.clear();
         //   System.out.println("=========" + aPoints.size());
            int ii = 0;
            for (Point point : aPoints) {
          //      System.out.println("=========" + point.getId() + point.getName());
                TranServiceRoute tranServiceRoute = new TranServiceRoute();
                tranServiceRoute.setPoint(point);
              //  System.out.println("point====="+point.getName()+"=========away"+ ii+2);
                tranServiceRoute.setAwayOrder(ii + 2);
                tsrs.add(tranServiceRoute);
                ii++;
            }

            for (int i = 0; i < hPoints.size(); i++) {
      
                Point point = hPoints.get(i);
               //   System.out.println("point====="+point.getName()+"=========home"+ i+1);
                boolean flag = false;
                for (TranServiceRoute route : tsrs) {
                    if (route.getPoint().getId() == point.getId()) {
                        route.setHomeOrder(i + 2);
                        flag = true;
                        break;
                    }
                }
                if (flag == false) {
                    TranServiceRoute tranServiceRoute = new TranServiceRoute();
                    tranServiceRoute.setPoint(point);
                    tranServiceRoute.setHomeOrder(i + 2);
                    tsrs.add(tranServiceRoute);
                }
            }

            tranService.setTerminalByTerminal1(t1);
            tranService.setTerminalByTerminal2(t2);

            TranServiceRoute tranServiceRoute = new TranServiceRoute();
            tranServiceRoute.setPoint(t1.getPoint());
            tranServiceRoute.setHomeOrder(hPoints.size() + 2);
            tranServiceRoute.setAwayOrder(1);
            tsrs.add(tranServiceRoute);
            tranServiceRoute = new TranServiceRoute();
            tranServiceRoute.setPoint(t2.getPoint());
            tranServiceRoute.setAwayOrder(aPoints.size() + 2);
            tranServiceRoute.setHomeOrder(1);
            tsrs.add(tranServiceRoute);
            tranService.getTranServiceRoutes().clear();
            tranService.getTranServiceRoutes().addAll(tsrs);

        }

        return event.getNewStep();

    }

    public void showmarker(LatLng latLng) {
        simpleModel.getCircles().clear();
        Circle circle2 = new Circle(latLng, 100);
        circle2.setStrokeColor("#00ff00");
        circle2.setFillColor("#00ff00");
        circle2.setStrokeOpacity(0.7);
        circle2.setFillOpacity(0.7);
        simpleModel.addOverlay(circle2);
    }

//load TST AT
    public void handleTSTChange() {
        try {
           // System.out.println("empty SYSTEM===========>{TSTID}=============:" + tstid);
            if (tstid != null && !tstid.equals("")) {

                TST.setId(Integer.parseInt(tstid));
                for (Map.Entry<String, String> e : tST.entrySet()) {
                    String key = e.getKey();
                    String value = e.getValue();
                    if (value.equals(tstid)) {
                        TST.setName(key);

                    }
                }
                List<TranServiceTypeAttribute> tranServiceTypeIndex = vtsta.getTranServiceTypeIndex(Integer.parseInt(tstid));

                tSTAttributeTypes = new ListDataModel<TranServiceTypeAttribute>(tranServiceTypeIndex);
                List<AttributeType> allAttribute = ats.getAllAttribute();
                List<AttributeType> allAttribute2 = new ArrayList<AttributeType>();

                aT.clear();
                tranServiceAttributesList.clear();
                tranServiceAttributesDataModel = new ListDataModel<TranServiceAttribute>(tranServiceAttributesList);

                for (AttributeType attributeType : allAttribute) {

                    for (TranServiceTypeAttribute tranServiceTypeAttribute : tranServiceTypeIndex) {
                        if (attributeType.getId() == tranServiceTypeAttribute.getAttributeType().getId()) {
                            allAttribute2.add(attributeType);
                        }

                    }

                }
                for (AttributeType attributeType : allAttribute2) {
                    allAttribute.remove(attributeType);
                }
                for (AttributeType attributeType : allAttribute) {
                    aT.put(attributeType.getName(), "" + attributeType.getId());
                }
            } else {
                tSTAttributeTypes = new ListDataModel<TranServiceTypeAttribute>();
                List<AttributeType> allAttribute = ats.getAllAttribute();
                aT.clear();
                for (AttributeType attributeType : allAttribute) {

                    aT.put(attributeType.getName(), "" + attributeType.getId());

                }
            }

        } catch (UniformInterfaceException ex) {
            Logger.getLogger(TranServiceBeanWizerd.class.getName()).log(Level.SEVERE, null, ex);
        } catch (JSONException ex) {
            Logger.getLogger(TranServiceBeanWizerd.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void addatttolist() {
       // System.out.println("SYSTEM===========>{atvalue}=============:" + atvalue + "===========>{atvaatidlue}=============:" + atid);
        if (atid != null && atvalue != null && !atid.equals("") && !atvalue.equals("")) {
            try {
                TranServiceAttribute tsa = new TranServiceAttribute();
                TranServiceTypeAttributeType tstat = new TranServiceTypeAttributeType();

                AttributeType at = new AttributeType(Integer.parseInt(atid));
                List<AttributeType> allAttribute = ats.getAllAttribute();
                for (AttributeType attributeType : allAttribute) {
                    if (attributeType.getId() == at.getId()) {
                        at = attributeType;
                    }
                }

                if (at.getIsNumber()) {
                    try {
                        double parseDouble = Double.parseDouble(atvalue);

                        tsa.setValue("" + parseDouble);
                        tstat.setAttributeType(at);
                        tsa.setTranServiceTypeAttributeType(tstat);
                        tranServiceAttributesList.add(tsa);
                        tranServiceAttributesDataModel = new ListDataModel<TranServiceAttribute>(tranServiceAttributesList);
                        String key = "-1";
                        for (Map.Entry<String, String> e : aT.entrySet()) {

                            String value = e.getValue();
                            if (value.equals(atid)) {
                                key = e.getKey();
                                at.setName(key);

                            }
                        }
                        aT.remove(key);
                    } catch (NumberFormatException e) {
                        FacesContext context = FacesContext.getCurrentInstance();
                        context.addMessage(null, new FacesMessage(at.getName(), "value must be number "));
                    }
                } else {
                    tsa.setValue(atvalue);
                    String key = "-1";
                    for (Map.Entry<String, String> e : aT.entrySet()) {

                        String value = e.getValue();
                        if (value.equals(atid)) {
                            key = e.getKey();
                            at.setName(key);

                        }
                    }
                    aT.remove(key);
                    tstat.setAttributeType(at);
                    tsa.setTranServiceTypeAttributeType(tstat);
                    tranServiceAttributesList.add(tsa);
                    tranServiceAttributesDataModel = new ListDataModel<TranServiceAttribute>(tranServiceAttributesList);

                }
            } catch (JSONException ex) {
                Logger.getLogger(TranServiceBeanWizerd.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    public void onMarkerSelect(OverlaySelectEvent event) {
        FacesContext context = FacesContext.getCurrentInstance();

        if (event.getOverlay() instanceof org.primefaces.model.map.Marker) {
            Marker marker = (Marker) event.getOverlay();
          //  System.out.println("asdasdas==========");
            if (counter == 0) {

             //   System.out.println("t1marker" + marker.getTitle() + "=======" + marker.getData().toString() + "===========" + marker.getLatlng());
                int parseInt = Integer.parseInt(marker.getData().toString());
                for (Terminal terminal : terminals) {
                    if (parseInt == terminal.getPoint().getId()) {
                        terminalMarkers.add(marker);
                        context.addMessage("sd", new FacesMessage("Terminal One", "successfuly added terminal One"));
                   //     System.out.println("asdasdas==========" + counter);
                        counter++;
                    }
                }
             //   System.out.println("asdasdas==========" + counter);
                if (counter == 0) {
                    context.addMessage(null, new FacesMessage("Terminal", "Select your terminals first"));
                }

            } else if (counter == 1) {

                if (!marker.equals(terminalMarkers.get(0))) {

               //     System.out.println("t2marker" + marker.getTitle() + "=======" + marker.getData().toString() + "===========" + marker.getLatlng());
                    int parseInt = Integer.parseInt(marker.getData().toString());
                    for (Terminal terminal : terminals) {
                        if (parseInt == terminal.getPoint().getId()) {
                            terminalMarkers.add(marker);
                            context.addMessage("sd", new FacesMessage("Terminal Two", "successfuly added terminal Two"));
                            context.addMessage("sd", new FacesMessage("successful addition of terminals", "You can add any Points Now!"));
                    //        System.out.println("asdasdas==========" + counter);
                            counter++;
                        }
                    }
                  //  System.out.println("asdasdas==========" + counter);
                    if (counter == 1) {
                        context.addMessage(null, new FacesMessage("Terminal", "Select your terminals first"));
                    }

                } else {
                    context.addMessage(null, new FacesMessage("Terminal", "you can't select the same Terminal"));
                }
            } else {
                if (!marker.equals(terminalMarkers.get(0)) && !marker.equals(terminalMarkers.get(1))) {
                    if (Saved) {
                        boolean flag = false;
                        for (Marker m : hpointsMarkers) {
                            if (m.equals(marker)) {
                                flag = true;
                            }
                        }
                        if (!flag) {
                            hpointsMarkers.add(marker);
                        } else {
                            context.addMessage(null, new FacesMessage("Point", "you can't select this point agian"));
                        }
                    } else {
                        boolean flag = false;
                        for (Marker m : pointsMarkers) {
                            if (m.equals(marker)) {
                                flag = true;
                            }
                        }
                        if (!flag) {
                            pointsMarkers.add(marker);
                        }
                    }
                } else {
                    context.addMessage(null, new FacesMessage("Point", "you can't select your terminal to act as a point"));
                }
            }
        }
    }

    public void clearall() {
       // System.out.println("sdsdsd-=--==--=--==-=--=-=-=-=--=-=-=-=-==-=-=-=-=-==--==");
        request = "";
        counter = 0;
        t1Lat = 0.0;
        t1Lng = 0.0;
        t2Lat = 0.0;
        t2Lng = 0.0;
        terminalMarkers = new ArrayList<Marker>();
        pointsMarkers = new ArrayList<Marker>();
    }

    public void clearallForHome() {
       // System.out.println("sdsdsd-=--==--=--==-=--=-=-=-=--=-=-=-=-==-=-=-=-=-==--==");
        requesth = "";
        hpointsMarkers = new ArrayList<Marker>();
    }

    public void save() {
        if (!terminalMarkers.isEmpty()) {
            request = "";
            requesth = "";
            t1Lat = terminalMarkers.get(0).getLatlng().getLat();
            t1Lng = terminalMarkers.get(0).getLatlng().getLng();
            t2Lat = terminalMarkers.get(1).getLatlng().getLat();
            t2Lng = terminalMarkers.get(1).getLatlng().getLng();
            if (terminalMarkers.size() == 2) {
                for (Marker point : pointsMarkers) {
                    request += point.getLatlng().getLat() + "," + point.getLatlng().getLng() + ";";
                }
                for (Marker point : hpointsMarkers) {
                    requesth += point.getLatlng().getLat() + "," + point.getLatlng().getLng() + ";";
                }
            } else {
             //   System.out.println("null");
            }
        } else {
            FacesContext context = FacesContext.getCurrentInstance();
            context.addMessage(null, new FacesMessage("Draw Route", "you Must Select at least the terminals"));
        }
    }

    public void newPoint() {
        try {
         //   System.out.println("newPoint======" + lat + "," + lng + " title: " + title);
            if (type.equals("Terminal")) {
                Point p = new Point();
                p.setLocation("(" + lat + "," + lng + ")");
                p.setName(title);
                p.setIsStop(true);
                Point addpoint = pointService.addpoint(p, true);
                terminals.add(new Terminal(addpoint));
                Marker marker2 = new Marker(toLatLng(addpoint.getLocation()), addpoint.getName(), "" + addpoint.getId(), "http://localhost:8080/GPAdminWebApplication/resources/images/terminal.png");
                marker2.setZindex(-1);
                simpleModel.addOverlay(marker2);
            } else if (type.equals("Stop")) {
                Point p = new Point();
                p.setLocation("(" + lat + "," + lng + ")");
                p.setName(title);
                p.setIsStop(true);
                Point addpoint = pointService.addpoint(p, false);
                points.add(addpoint);
                Marker marker2 = new Marker(toLatLng(addpoint.getLocation()), addpoint.getName(), "" + addpoint.getId(), "http://localhost:8080/GPAdminWebApplication/resources/images/stop.png");
                marker2.setZindex(-1);
                simpleModel.addOverlay(marker2);
            } else {
                Point p = new Point();
                p.setLocation("(" + lat + "," + lng + ")");
                p.setName(title);
                p.setIsStop(false);
                Point addpoint = pointService.addpoint(p, false);
                points.add(addpoint);
                Marker marker2 = new Marker(toLatLng(addpoint.getLocation()), addpoint.getName(), "" + addpoint.getId(), "http://localhost:8080/GPAdminWebApplication/resources/images/point.png");
                marker2.setZindex(-1);
                simpleModel.addOverlay(marker2);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void updateatints(){
        try {
            if(vtsta !=null){
                if(tstid!=null){
            List<TranServiceTypeAttribute> tranServiceTypeIndex = vtsta.getTranServiceTypeIndex(Integer.parseInt(tstid));
            
            List<AttributeType> allAttribute = ats.getAllAttribute();
            List<AttributeType> allAttribute2 = new ArrayList<AttributeType>();
            
            aT.clear();
            
            for (AttributeType attributeType : allAttribute) {
                
                for (TranServiceTypeAttribute tranServiceTypeAttribute : tranServiceTypeIndex) {
                    if (attributeType.getId() == tranServiceTypeAttribute.getAttributeType().getId()) {
                        allAttribute2.add(attributeType);
                    }

                }
                
            }
            for (AttributeType attributeType : allAttribute2) {
                allAttribute.remove(attributeType);
            }
            for (AttributeType attributeType : allAttribute) {
                aT.put(attributeType.getName(), "" + attributeType.getId());
            }
            
            for (TranServiceAttribute tsa : tranServiceAttributesList) {
                String key = "-1";
                for (Map.Entry<String, String> e : aT.entrySet()) {
                    
                    String value = e.getValue();
                    if (tsa.getTranServiceTypeAttributeType().getAttributeType().getId() == Integer.parseInt(value)) {
                        key = e.getKey();
                        
                    }
                }
                aT.remove(key);
            }
            }
                else{
                    ats = new AttributeTypeService();
             List<AttributeType> allAttribute = ats.getAllAttribute();
                for (AttributeType attributeType : allAttribute) {

                    aT.put(attributeType.getName(), "" + attributeType.getId());

                }
            }
            }
        } catch (JSONException ex) {
            Logger.getLogger(ViewAndEditTranServiceBean.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

     public void updatetstints(){
         System.err.println("[[][][]][]][][][][][][][][][][][][][][][][][]]]]]]]]]]");
         tST.clear();
         if(vtsta == null){
             vtsta = new ViewTransServiceTypeAtt();
         }else{
        try {
            List<TranServiceType> tranServiceTypes = vtsta.getTranServiceTypes();
            for (TranServiceType tranServiceType : tranServiceTypes) {
                tST.put(tranServiceType.getName(), "" + tranServiceType.getId());
            }
        } catch (UniformInterfaceException ex) {
            Logger.getLogger(ViewAndEditTranServiceBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (JSONException ex) {
            Logger.getLogger(ViewAndEditTranServiceBean.class.getName()).log(Level.SEVERE, null, ex);
        }
         }
    }
    // ============ hellper method=====
    private LatLng toLatLng(String location) {
        String removeb1 = location.substring(1, location.length());
        String removeb2 = removeb1.substring(0, removeb1.length() - 1);
        String[] split = removeb2.split(",");
        return new LatLng(Double.parseDouble(split[0]), Double.parseDouble(split[1]));
    }
//==========setter and getter ==============

    public List<Marker> getTerminalMarkers() {
        return terminalMarkers;
    }

    public void setTerminalMarkers(List<Marker> terminalMarkers) {
        this.terminalMarkers = terminalMarkers;
    }

    public List<Marker> getPointsMarkers() {
        return pointsMarkers;
    }

    public void setPointsMarkers(List<Marker> pointsMarkers) {
        this.pointsMarkers = pointsMarkers;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public double getLat() {
        return lat;
    }

    public void setLat(double lat) {
        this.lat = lat;
    }

    public double getLng() {
        return lng;
    }

    public void setLng(double lng) {
        this.lng = lng;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public MapModel getSimpleModel() {
        return simpleModel;
    }

    public void setSimpleModel(MapModel simpleModel) {
        this.simpleModel = simpleModel;
    }

    public String getRequest() {
        return request;
    }

    public void setRequest(String request) {
        this.request = request;
    }

    public double getT1Lat() {
        return t1Lat;
    }

    public void setT1Lat(double t1Lat) {
        this.t1Lat = t1Lat;
    }

    public double getT1Lng() {
        return t1Lng;
    }

    public void setT1Lng(double t1Lng) {
        this.t1Lng = t1Lng;
    }

    public double getT2Lat() {
        return t2Lat;
    }

    public void setT2Lat(double t2Lat) {
        this.t2Lat = t2Lat;
    }

    public double getT2Lng() {
        return t2Lng;
    }

    public void setT2Lng(double t2Lng) {
        this.t2Lng = t2Lng;
    }

    public String getAtvalue() {
        return atvalue;
    }

    public void setAtvalue(String atvalue) {
        this.atvalue = atvalue;
    }

    public List<Point> getaPoints() {
        return aPoints;
    }

    public void setaPoints(List<Point> aPoints) {
        this.aPoints = aPoints;
    }

    public Terminal getT1() {
        return t1;
    }

    public void setT1(Terminal t1) {
        this.t1 = t1;
    }

    public Terminal getT2() {
        return t2;
    }

    public void setT2(Terminal t2) {
        this.t2 = t2;
    }

    public TranService getTranService() {
        return tranService;
    }

    public void setTranService(TranService tranService) {
        this.tranService = tranService;
    }

    public String getTstid() {
        return tstid;
    }

    public void setTstid(String tstid) {
        this.tstid = tstid;
    }

    public Map<String, String> gettST() {
        return tST;
    }

    public void settST(Map<String, String> tST) {
        this.tST = tST;
    }

    public boolean isSkip() {
        return skip;
    }

    public void setSkip(boolean skip) {
        this.skip = skip;
    }

    public DataModel<TranServiceTypeAttribute> gettSTAttributeTypes() {
        return tSTAttributeTypes;
    }

    public void settSTAttributeTypes(DataModel<TranServiceTypeAttribute> tSTAttributeTypes) {
        this.tSTAttributeTypes = tSTAttributeTypes;
    }

    public Map<String, String> getaT() {
        return aT;
    }

    public void setaT(Map<String, String> aT) {
        this.aT = aT;
    }

    public String getAtid() {
        return atid;
    }

    public void setAtid(String atid) {
        this.atid = atid;
    }

    public DataModel<TranServiceAttribute> getTranServiceAttributesDataModel() {
        return tranServiceAttributesDataModel;
    }

    public void setTranServiceAttributesDataModel(DataModel<TranServiceAttribute> tranServiceAttributesDataModel) {
        this.tranServiceAttributesDataModel = tranServiceAttributesDataModel;
    }

    public List<Marker> getHpointsMarkers() {
        return hpointsMarkers;
    }

    public void setHpointsMarkers(List<Marker> hpointsMarkers) {
        this.hpointsMarkers = hpointsMarkers;
    }

    public String getRequesth() {
        return requesth;
    }

    public void setRequesth(String requesth) {
        this.requesth = requesth;
    }

    public TranServiceType getTST() {
        return TST;
    }

    public void setTST(TranServiceType TST) {
        this.TST = TST;
    }

    public List<TranServiceRoute> getTsrs() {
        return tsrs;
    }

    public void setTsrs(List<TranServiceRoute> tsrs) {
        this.tsrs = tsrs;
    }

    public void add() {
        try {
            String addTranService = tss.addTranService(tranService);
            FacesContext context = FacesContext.getCurrentInstance();
            context.addMessage(null, new FacesMessage("Message", addTranService));
        } catch (UniformInterfaceException ex) {
            Logger.getLogger(TranServiceBeanWizerd.class.getName()).log(Level.SEVERE, null, ex);
        } catch (JSONException ex) {
            Logger.getLogger(TranServiceBeanWizerd.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    public void test(){
        System.out.println("================================+soso za3lanaah heya el 3'altana akalet werk el far5a el far5a fel namlia a5s 3aleky ya 2ota etfo5s");
    }
}
